package com.compass.doctor.ui.home

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.compass.doctor.databinding.ActivityTeamDoctorBinding
import com.compass.doctor.ui.home.fragment.DoctorManagementFragment
import com.compass.doctor.ui.home.fragment.InquiryPatientFragment
import com.compass.doctor.ui.home.fragment.PatientManagementFragment
import com.compass.framework.adapter.ViewPage2FragmentAdapter
import com.compass.doctor.base.BaseVBActivity
import com.compass.framework.constant.KEY_ORDER_TYPE

/**
 * Description： 团队医生
 * Date:2023/12/23 14:18
 */
class TeamDoctorActivity : BaseVBActivity<ActivityTeamDoctorBinding>(){


    companion object {
        fun start(context: Context) {
            val intent = Intent(context, TeamDoctorActivity::class.java)
            context.startActivity(intent)
        }
    }


    private lateinit var viewPageAdapter: ViewPage2FragmentAdapter
    private var fragments: ArrayList<Fragment> = ArrayList()

    private lateinit var inquiryPatientFragment: InquiryPatientFragment
    private lateinit var patientManagementFragment: PatientManagementFragment
    private lateinit var doctorManagementFragment: DoctorManagementFragment

    override fun initView(savedInstanceState: Bundle?) {
        initFragment()
        mBinding.dslTab.tabIndicator.indicatorWidth = -2
        mBinding.dslTab.tabIndicator.indicatorEnableFlow = true
        mBinding.dslTab.configTabLayoutConfig {
            onSelectIndexChange = { fromIndex, selectIndexList, reselect, fromUser ->
                val toIndex = selectIndexList.first()
                mBinding.viewpager2.setCurrentItem(toIndex, false)

            }
        }
        viewPageAdapter = ViewPage2FragmentAdapter(supportFragmentManager, lifecycle, fragments)
        mBinding.viewpager2.adapter = viewPageAdapter
        mBinding.viewpager2.isUserInputEnabled = false//禁止viewPage滑动
        mBinding.viewpager2.setCurrentItem(0, false)

    }

    private fun initFragment() {
        inquiryPatientFragment = InquiryPatientFragment()
        val bundleReception = Bundle()
        bundleReception.putInt(KEY_ORDER_TYPE, 1)
        inquiryPatientFragment.arguments = bundleReception
        fragments.add(inquiryPatientFragment)

        patientManagementFragment = PatientManagementFragment()
        val bundleAlready = Bundle()
        bundleAlready.putInt(KEY_ORDER_TYPE, 2)
        patientManagementFragment.arguments = bundleAlready
        fragments.add(patientManagementFragment)

        doctorManagementFragment = DoctorManagementFragment()
        val bundleComplete = Bundle()
        bundleAlready.putInt(KEY_ORDER_TYPE, 2)
        doctorManagementFragment.arguments = bundleComplete
        fragments.add(doctorManagementFragment)


    }
}